text: Treat Emoji insertion like clipboard
authorMatthias Clasen <mclasen@redhat.com>
Mon, 17 Feb 2020 20:05:09 +0000 (15:05 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 17 Feb 2020 20:05:09 +0000 (15:05 -0500)
Enter the Emoji inseration in the undo history.
Also, stop stashing away the selection when we
pop up the Emoji chooser, and use the selection
as-is when we insert the Emoji.

gtk/gtktext.c

index b671c9a39f680212db60e4b6a035b06ba36f0e99..4f428ba8f9d1e9a54eed323f1796aeb31ec4106e 100644 (file)
@@ -6779,20 +6779,23 @@ emoji_picked (GtkEmojiChooser *chooser,
               const char      *text,
               GtkText         *self)
 {
-  int current_pos;
-  int selection_bound;
+  int pos;
 
-  current_pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (chooser), "current-pos"));
-  selection_bound = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (chooser), "selection-bound"));
+  GtkTextPrivate *priv = gtk_text_get_instance_private (self);
 
-  gtk_text_set_positions (self, current_pos, selection_bound);
-  gtk_text_enter_text (self, text);
+  begin_change (self);
+  if (priv->selection_bound != priv->current_pos)
+    gtk_text_delete_selection (self);
+
+  pos = priv->current_pos;
+  gtk_text_insert_text (self, text, -1, &pos);
+  gtk_text_set_selection_bounds (self, pos, pos);
+  end_change (self);
 }
 
 static void
 gtk_text_insert_emoji (GtkText *self)
 {
-  GtkTextPrivate *priv = gtk_text_get_instance_private (self);
   GtkWidget *chooser;
 
   if (gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_EMOJI_CHOOSER) != NULL)
@@ -6808,9 +6811,6 @@ gtk_text_insert_emoji (GtkText *self)
       g_signal_connect (chooser, "emoji-picked", G_CALLBACK (emoji_picked), self);
     }
 
-  g_object_set_data (G_OBJECT (chooser), "current-pos", GINT_TO_POINTER (priv->current_pos));
-  g_object_set_data (G_OBJECT (chooser), "selection-bound", GINT_TO_POINTER (priv->selection_bound));
-
   gtk_popover_popup (GTK_POPOVER (chooser));
 }